package com.xyc.javase.stringtest;

/**
 * @Version 1.0
 * @Author:徐衍程
 * @Date:2022/4/6
 * @Content:
 */
public class StringOrder {

    public static void main(String[] args) {
//        统计字符出现次数
        String str = "aaabbcaaaaa";
        sumTimes(str);//a3b2c1a5

    }

    private static void sumTimes(String str) {
        char[] arr = str.toCharArray();
        int count = 1;
        char temp = arr[0];
        StringBuilder strs = new StringBuilder();
        strs.append(arr[0]);
        for (int i = 1; i<arr.length;i++){
            if(temp == arr[i]){
                count ++;
            }else {
                strs.append(count);
                count = 1;
                temp = arr[i];
                strs.append(arr[i]);
            }
        }
        strs.append(count);
        System.out.println(strs.toString());
    }


}
